<?php
/**
 * Created by PhpStorm.
 * User: wuchao
 * Date: 2020/4/17
 * Time: 14:35
 */

namespace app\api\controller\v1\home;


use app\api\model\CateGoryModel;
use app\middleware\ApiAuth;
use think\Request;
use think\facade\Validate;
use think\response\Json;
use think\validate\ValidateRule;

/**
 * Class C端分类控制器
 * @package app\controller
 */
class CateGory
{
    protected $middleware = [ApiAuth::class];

    /**
     * @desc 一级分类
     * @return Json
     */
    public function OneCategory(Request $request)
    {
        $input['admin_id'] = $request->param('admin_id');//运营商ID
        // 参数校验
        $validate = Validate::rule([
            'admin_id' => ValidateRule::isRequire(),
        ]);
        if (!$validate->check($input)) {
            return jsonFail($validate->getError());
        }
        //逻辑处理
        return CateGoryModel::OneCategory($input);//TODO 一级分类
    }

    /**
     * @desc 二级分类
     * @return Json
     */
    public function TwoCategory(Request $request)
    {
        $input['admin_id'] = $request->param('admin_id');//code
        $input['id'] = $request->param('id');//一级ID
        // 参数校验
        $validate = Validate::rule([
            'id' => ValidateRule::isRequire(),
            'admin_id' => ValidateRule::isRequire(),
        ]);
        if (!$validate->check($input)) {
            return jsonFail($validate->getError());
        }
        //逻辑处理
        return CateGoryModel::TwoCategory($input);//TODO 二级分类
    }
    /**
     * @desc 三级分类和商品
     * @return Json
     */
    public function ThreeCategory(Request $request)
    {
        $input['admin_id'] = $request->param('admin_id');//二级运营ID
        $input['id'] = $request->param('id');//二级ID
        // 参数校验
        $validate = Validate::rule([
            'id' => ValidateRule::isRequire(),
            'admin_id' => ValidateRule::isRequire(),
        ]);
        if (!$validate->check($input)) {
            return jsonFail($validate->getError());
        }
        //逻辑处理
        return CateGoryModel::ThreeCategory($input);//TODO 三级分类
    }
}